//
// Created by 29001 on 2024/11/21.
//

#include "row.h"

/*
 * Serialize the data of the structure Row to a contiguous memory area
 */
void serialize_row(Row *source, void *destination) {
    memcpy(destination + ID_OFFSET, &(source->id), ID_SIZE);
    memcpy(destination + USERNAME_OFFSET, &(source->username), USERNAME_SIZE);
    memcpy(destination + EMAIL_SIZE, &(source->email), EMAIL_SIZE);
}

/*
 * restore it to the structure Row
 */
void deserialize_row(void *source, Row *destination) {
    memcpy(&(destination->id), source + ID_OFFSET, ID_SIZE);
    memcpy(&(destination->username), source + USERNAME_OFFSET, USERNAME_SIZE);
    memcpy(&(destination->email), source + EMAIL_OFFSET, EMAIL_SIZE);
}

/*
 * here print the row of the table
 */
void print_row(Row *row) {
    printf("here print the row of the table\n");
    printf("(%d, %s, %s)\n", row->id, row->username, row->email);
}